from django.db import models

from main.models import Article
from user.models import CustomUser


# Create your models here.

class Collect(models.Model):
    article = models.ForeignKey(verbose_name="文章", to=Article, on_delete=models.CASCADE)
    user = models.ForeignKey(verbose_name="用户", to=CustomUser, on_delete=models.CASCADE)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")

    def __str__(self):
        return f"用户:{self.user.username}收藏  文章{self.article.title}"

    class Meta:
        unique_together = ("article", "user")